(function(){
	var menu=$("<li callFunc='click:descHandle.getFile'>查看文件内容</li>");
	yanhx.addFunc("getFile",function(){
		menu.menu(this);
	});
	var typeDesc={
		field:"<span style='width:300px' class='fieldDiv submitField' callFunc='menu:getFile click:singleField' model='single' action='table'></span>",	
		mutilField:"<span style='width:300px' class='fieldDiv submitField' callFunc='click:singleField' action='service'></span>"
	};
	var compDesc={
		loginData:{type:"mutilField",name:"登录信息"},
		text:{type:"mutilField",name:"文件文件"},
		data:{type:"mutilField",name:"数据字典"},
		pageTitle:'页面标题',
		devModel:{html:'<select name="devModel" class="submitField"><option value="false" >生产模式</option><option value="true" >开发模式</option></select>',name:'模式'},
		jsImport:{type:"field",name:"js文件"},
		cssImport:{type:"field",name:"css文件"},
		tableHead:{type:"field",name:"表头配置"},
		title:'标题',
		hasSub:{html:'<select name="hasSub" class="submitField"><option value="true" >父节点</option><option value="false" checked=true >子节点</option></select>',name:'字段类型'},
		thead:'表格head',
		event:'事件',
		remark:'备注',
		keyup:'keyup',
		param:'参数',
		width:'宽度',
		height:'高度',
		subName:'子节点',
		action:'服务名称',
		fieldType:{html:'<select name="fieldType" class="submitField"><option value="mutil" >多选</option><option value="single" checked=true >单选</option></select>',name:'字段类型'},
		pageSize:"每页条数",
		template:{type:"field",name:"模板"},
		head:{type:"field",name:"头配置"},
		query:{type:"field",name:"查询配置"},
		other:{html:'<textarea name="other" class="submitField"></textarea>',name:'其他',oneRow:true}
	};
	yanhx.addComponent("descHandle",{
		save:function(src){
			var bean=src.parent().getBean();
			$.postJSON("/do?action=table.saveFile",bean,function(ret){
				$.warn(ret.message);
				yanhx.exec("myWin.closeWin");
			});
		},
		getFile:function(){
			var src=$.menu("getSrc");
			var fileName=src.text();
			$.postJSON("/do?action=table.getFile",{name:fileName},function(ret){
				var div=$("<div style='text-align:center;width:500px;'>");
				var text=$("<textarea name='text' class='submitField' style='width:100%;height:300px;'></textarea>").appendTo(div);
				text.val(ret.text);
				$("<input type=hidden name='name' class='submitField' />").val(fileName).appendTo(div);
				$("<button callFunc='click:descHandle.save' class='btn'>保存</button>").appendTo(div);
				div.modelWin();
			});
		},
		resetData:function(data){
			for(var k in data){
				if(compDesc[k]&&compDesc[k].dt){
					if(compDesc[k].dt=="json"){
						data[k]=JSON.parse(data[k]);
					}
				}
			}
		}
	});
	//默认参数
	var defParam={
		id:'id',
		name:'名称',
		cl:'class',	
		valid:'验证规则',
		errorMsg:'错误信息',
		noNull:{html:'<select name="noNull" class="submitField"><option value="false" checked=true >是</option><option value="true" >否</option></select>',name:'是否可空'},	
		noescape:{html:'<select name="noescape" class="submitField"><option value="false"  checked=true >是</option><option value="true" >否</option></select>',name:'是否编码'}
	};
	//参数作为样式处理
	var cssParam=",width,height,float,";
	yanhx.addFunc("_form_param",function(param){
		param.elem.empty();
		param.elem.parent().show();
		_yanhx_11(param.elem,defParam);
		param.elem.append("<div class='splitDiv'>模板定义参数</div>");
		_yanhx_10(param.elem,param.data);
		param.elem.fill(param.data);
	});
	function _yanhx_11(editDiv,code){
		for(var key in code){
			var desc=code[key];
			if(typeof(desc)=="string"){
				$("<span><label>"+desc+"</label><input name="+key+" class='submitField'></input></span>").appendTo(editDiv);
			}else{
				if(desc.oneRow){
					editDiv.append("<div style='clear:both'><label>"+desc.name+"</label>"+desc.html+"</div>");
				}
				else{
					$("<span><label>"+desc.name+"</label>"+desc.html+"</span>").appendTo(editDiv);
				}
			}
		}
	}
	function _yanhx_10(editDiv,code){
		for(var key in code){
			var val=code[key];
			var desc=compDesc[key];
			if(!desc) continue;
			if(defParam[key]){

			}
			else if(typeof(desc)=="string"||!desc){
				$("<span><label>"+desc+"</label><input name="+key+" class='submitField'></input></span>").appendTo(editDiv);
			}else{
				if(desc.type){
					var span=$("<span><label>"+desc.name+"</label></span>").appendTo(editDiv);
					$(typeDesc[desc.type]).attr("title",desc.name).attr("name",key).appendTo(span);
				}
				else if(desc.oneRow){
					editDiv.append("<div style='clear:both'><label>"+desc.name+"</label>"+desc.html+"</div>");
				}
				else{
					$("<span><label>"+desc.name+"</label>"+desc.html+"</span>").appendTo(editDiv);
				}
			}
		}
	}
})();